package com.tbit.uqbike.client.service.impl;

import com.tbit.uqbike.client.dao.core.ZfbPayConfigDao;
import com.tbit.uqbike.client.pojo.ZfbPayConfig;
import com.tbit.uqbike.client.service.CacheService;
import com.tbit.uqbike.client.service.ZfbPayConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service("zfbPayConfigService")
public class ZfbPayConfigServiceImpl implements ZfbPayConfigService {
    @Autowired
    private ZfbPayConfigDao zfbPayConfigDao;
    @Autowired
    private CacheService cacheService;

    @Override
    public ZfbPayConfig getByAccountId(Integer accountId, Integer type) {
        return cacheService.getZfbPay(accountId, type);
		/*Map<String,Object> map = new HashMap<>();
		map.put("accountId",accountId);
		map.put("type",type);
		return zfbPayConfigDao.getByAccountId(map);*/
    }

    @Override
    public void add(ZfbPayConfig zfbPayConfig) {
        ZfbPayConfig zfbPayConfigDB = getByAccountId(zfbPayConfig.getAccountId(), 1);
        if (zfbPayConfigDB != null) {
            if (zfbPayConfig.getRemark() == null) {
                zfbPayConfig.setRemark(zfbPayConfigDB.getRemark());
            }
            zfbPayConfigDao.edit(zfbPayConfig);
        } else {
            zfbPayConfigDao.add(zfbPayConfig);
        }
    }


}